<extend name="Public/base" />

<block name="style">
	<link rel="stylesheet" type="text/css" href="__STATIC__/qtip/jquery.qtip.min.css" media="all">
    <style>
	
	/* 授权编辑页 */
	.checkmod {
		margin-bottom: 20px;
		border: 1px solid #faeae6;
	}
	.checkmod dt {
		padding-left: 10px;
		height: 30px;
		line-height: 30px;
		font-weight: bold;
		border-bottom: 1px solid #faeae6;
		background-color: #faeae6;
	}
	.checkmod dd {
		padding-left: 10px;
		line-height: 30px;
	}
	.checkmod dd .checkbox {
		margin: 0 10px 0 0;
	}
	.checkmod dd .divsion {
		margin-right: 20px;
	}
	.checkbox, .radio {
		display: inline-block;
		height: 20px;
		line-height: 20px;
	}
	
	.checkmod .hd .checkbox {
		margin: 0;
	}

    .child_row {
        padding-left:30px;
        display: block;
    }
	</style>
</block>

<block name="body">

    <div class="row">
        <div class="col-md-12">
            
            <div class="tabbable tabbable-custom boxless">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="javascript:;">访问授权</a></li>
                    <li><a href="{:U('AuthManager/category',array('group_name'=>I('group_name') ,'group_id'=> I('group_id')))}">分类授权</a></li>
                    <li><a href="{:U('AuthManager/user',array('group_name'=>I('group_name') ,'group_id'=> I('group_id')))}">成员授权</a></li>
                </ul>
                
                <div class="tab-content">
            
                    
                    
                    <div class="portlet box red">
                        <div class="portlet-title">
                            <div class="caption"><i class="fa fa-reorder"></i>访问授权</div>
                            <div class="tools">
                                <select name="group">
                                    <volist name="auth_group" id="vo">
                                        <option value="{:U('AuthManager/access',array('group_id'=>$vo['id'],'group_name'=>$vo['title']))}" <eq name="vo['id']" value="$this_group['id']">selected</eq> >{$vo.title}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                        <div class="portlet-body form">
                            <!-- BEGIN FORM-->
                            
                                <div class="form-body">
                                
                					<form id="form" action="{:U('AuthManager/writeGroup')}"  method="post" class="form-1" enctype="application/x-www-form-urlencoded" >
                                    <volist name="node_list" id="node" >
                                        <dl class="checkmod">
                                            <dt class="hd">
                                                <label class="checkbox"><input class="auth_rules rules_all" type="checkbox" name="rules[]" value="<?php echo $main_rules[$node['url']] ?>">{$node.title}管理</label>
                                            </dt>
                                            <dd class="bd">
                                                <present name="node['child']">
                                                <volist name="node['child']" id="child" >
                                                    <div class="rule_check">
                                                        <div>
                                                            <label class="checkbox" <notempty name="child['tip']">title='{$child.tip}'</notempty>>
                                                           <input class="auth_rules rules_row" type="checkbox" name="rules[]" value="<?php echo $auth_rules[$child['url']] ?>"/>{$child.title}
                                                            </label>
                                                        </div>
                                                            <notempty name="child['operator']">
                                                               <span class="child_row">
                                                                   <volist name="child['operator']" id="op">
                                                                       <label class="checkbox" <notempty name="op['tip']">title='{$op.tip}'</notempty>>
                                                                           <input class="auth_rules" type="checkbox" name="rules[]"
                                                                           value="<?php echo $auth_rules[$op['url']] ?>"/>{$op.title}
                                                                       </label>
                                                                   </volist>
                                                               </span>
                                                            </notempty>
                                                        </div>
                                                </volist>
                                                </present>
                                            </dd>
                                        </dl>
                                    </volist>
                                    
                                </div>
                                
                                
                                <div class="form-actions fluid ">
                                    <div class="col-md-offset-3 col-md-9">
                                        <input type="hidden" name="id" value="{$this_group.id}">
                                        <button class="btn green submit-btn ajax-post" id="submit" type="submit" target-form="form-1">确 定</button>
                                        <button class="btn default btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>                      
                                    </div>
                                </div>
               					</form>
                            
                            <!-- END FORM--> 
                        </div>
                    </div>
                        
                </div>
                
            </div>
        </div>
    </div>
    
</block>
<block name="script">
	<!-- BEGIN PAGE LEVEL SCRIPTS -->
	<script src="__STATIC__/scripts/app.js"></script>
    <script type="text/javascript" src="__STATIC__/qtip/jquery.qtip.min.js"></script>
	<!-- END PAGE LEVEL SCRIPTS -->
	<script>
	jQuery(document).ready(function() {       
		// initiate layout and plugins
		App.init();

        highlight_subnav('{:U('AuthManager/index')}');
	})
	
    +function($){
        var rules = [{$this_group.rules}];
        $('.auth_rules').each(function(){
            if( $.inArray( parseInt(this.value,10),rules )>-1 ){
                $(this).prop('checked',true);
            }
            if(this.value==''){
                $(this).closest('span').remove();
            }
        });

        //全选节点
        $('.rules_all').on('change',function(){
            $(this).closest('dl').find('dd').find('input').prop('checked',this.checked);
			
			if(this.checked){
            	$(this).closest('dl').find('dd').find('span').addClass('checked');
			}else{
				$(this).closest('dl').find('dd').find('span').removeClass('checked');
			}
        });
        $('.rules_row').on('change',function(){
            $(this).closest('.rule_check').find('.child_row').find('input').prop('checked',this.checked);
			
			if(this.checked){
            	$(this).closest('.rule_check').find('.child_row').find('span').addClass('checked');
			}else{
				$(this).closest('.rule_check').find('.child_row').find('span').removeClass('checked');
			}
        });

        $('.checkbox').each(function(){
            $(this).qtip({
                content: {
                    text: $(this).attr('title'),
                    title: $(this).text()
                },
                position: {
                    my: 'bottom center',
                    at: 'top center',
                    target: $(this)
                },
                style: {
                    classes: 'qtip-dark',
                    tip: {
                        corner: true,
                        mimic: false,
                        width: 10,
                        height: 10
                    }
                }
            });
        });

        $('select[name=group]').change(function(){
			location.href = this.value;
        });
		
    }(jQuery);
</script>
</block>
